#ifndef WEBSERVER_HH
#define WEBSERVER_HH

#include "FTDI_Device.hpp"
#include "UrlHook.hh"
#include "System_log.hh"

using namespace std;


class QueryUrlHookCB;
class StartUrlHookCB;
class StopUrlHookCB;
class MyWebServer;

typedef TypedCallback <QueryUrlHookCB, MyWebServer *>  query_url_called_cb;

class QueryUrlHookCB
{
 public:
    // Override () operator, this function gets called when data is availiable
    virtual int operator()(query_url_called_cb *);
};

typedef TypedCallback <StartUrlHookCB, MyWebServer *>  start_url_called_cb;

class StartUrlHookCB
{
 public:
    // Override () operator, this function gets called when data is availiable
    virtual int operator()(start_url_called_cb *);
};

typedef TypedCallback <StopUrlHookCB, MyWebServer *>  stop_url_called_cb;

class StopUrlHookCB
{
 public:
    // Override () operator, this function gets called when data is availiable
    virtual int operator()(stop_url_called_cb *);
};

/* A class that is handling the main application logic.
 * It is derived from the Process class in order to become a CCS process.
 */
class MyWebServer
{
public:
    typedef enum {
        STOP = 0,
        RUN
    } relay_state_e;

private:
    relay_state_e status;
    
public:

    FTDI_Device    *ftdi_device;
    // Url Hook
    UrlHook *urlhook;

    // Call backs
#define QUERY_URL "Query"
    QueryUrlHookCB querycb; // Callback for http://127.0.0.1:3490/Query
#define START_URL "Start"
    StartUrlHookCB startcb; // Callback for http://127.0.0.1:3490/Start
#define STOP_URL "Stop"
    StopUrlHookCB  stopcb;  // Callback for http://127.0.0.1:3490/Stop

    // USB-Serial + I/O FTDI Device
    
public:
    MyWebServer();
    relay_state_e get_status(void);
    void relay_ON(void);
    void relay_OFF(void);
    int evt_loop(void);
};

static inline
void printLog(int level, char *str) 
{
	dbg_print(str);
}

#endif //WEBSERVER_HH
